<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职工号" prop="jobNumber">
        <el-input
          v-model="queryParams.jobNumber"
          placeholder="请输入职工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" filterable  placeholder="请选择">
          <el-option v-for="item in statusList"
                     :key="item.statusCode"
                     :label="item.statusName"
                     :value="item.statusCode"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工会" prop="deptId">
        <el-select v-model="queryParams.deptId" filterable  placeholder="请选择">
          <el-option v-for="item in deptList"
                     :key="item.deptId"
                     :label="item.deptName"
                     :value="item.deptId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:appWithdrawal:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:appWithdrawal:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:appWithdrawal:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:appWithdrawal:exp']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appWithdrawalList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="姓名" align="center" prop="params.realName" />
      <el-table-column label="职工号" align="center" prop="params.jobNumber" />
      <el-table-column label="退出工会" align="center" prop="params.deptName" />
      <el-table-column label="审核状态" align="center" prop="params.statusName" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-set-up"
            @click="auditSecondLaborUnion(scope.row)"
            v-hasPermi="['business:appWithdrawal:auditSecondLaborUnion']"
            :disabled="scope.row.status !='0'"
          >二级工会审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="auditFundCommittee(scope.row)"
            v-hasPermi="['business:appWithdrawal:auditFundCommittee']"
            :disabled="scope.row.status !='2'"
          >基金管委会审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 二级工会审核 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-form-item label="审核状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio label="2">通过</el-radio>
            <el-radio label="1">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见" prop="remark">
          <el-input v-model.trim="form.opinion" type="textarea" :rows="4" placeholder="请输入审核意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--基金管委会审核-->
    <el-dialog :title="title" :visible.sync="openFundCommittee" width="500px" append-to-body>
      <el-form ref="form" :model="formFundCommittee"  label-width="80px">
        <el-form-item label="审核状态" prop="status">
          <el-radio-group v-model="formFundCommittee.status">
            <el-radio label="3">通过</el-radio>
            <el-radio label="4">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见" prop="remark">
          <el-input v-model.trim="formFundCommittee.opinion" type="textarea" :rows="4" placeholder="请输入审核意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFundCommittee">确 定</el-button>
        <el-button @click="cancelFundCommittee">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAppWithdrawal, getAppWithdrawal, delAppWithdrawal, addAppWithdrawal, updateAppWithdrawal,
  auditSecondLaborUnion,auditFundCommittee} from "@/api/approval/appWithdrawal";
import { selectSecondDeptList } from "@/api/system/dept";
export default {
  name: "AppWithdrawal",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退会申请记录表格数据
      appWithdrawalList: [],
      //单位（二级工会）
      deptList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openFundCommittee: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        miniUserId: null,
        status: null,
        beginTime:null,
        endTime:null,
      },
      // 表单参数
      form: {
        id: null,
        status: "2",
        opinion: null
      },
      //基金管委会审核表单
      formFundCommittee: {
        id: null,
        status: "3",
        opinion: null
      },
      statusList:[
        {"statusCode":"0","statusName":"待二级工会审核"},
        {"statusCode":"1","statusName":"二级工会审核驳回"},
        {"statusCode":"2","statusName":"待基金管委会办公室审核"},
        {"statusCode":"3","statusName":"基金管委会办公室审核通过"},
        {"statusCode":"4","statusName":"基金管委会办公室审核驳回"},
      ],
      // 表单校验
      /*rules: {
        miniUserId: [
          { required: true, message: "小程序用户id不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "审核状态", trigger: "blur" }
        ],
      }*/
    };
  },
  created() {
    this.getList();
    this.selectSecondDeptList();
  },
  methods: {
    /** 查询退会申请记录列表 */
    getList() {
      this.loading = true;
      if(this.dateRange !=null) {
        this.queryParams.beginTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
      }else {
        this.queryParams.beginTime = null;
        this.queryParams.endTime = null;
      }
      listAppWithdrawal(this.queryParams).then(response => {
        this.appWithdrawalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    selectSecondDeptList() {
      selectSecondDeptList().then(response => {
        this.deptList = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelFundCommittee() {
      this.openFundCommittee = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: "2",
        opinion: null
      };
      this.resetForm("form");
    },
    resetFormFundCommittee() {
      this.formFundCommittee = {
        id: null,
        status: "3",
        opinion: null
      };
      this.resetForm("formFundCommittee");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 二级工会审核 */
    auditSecondLaborUnion(row) {
      this.reset();
      this.form.id=row.id;
      this.open = true;
      this.title = "二级工会审核";
    },
    /** 管委会审核 */
    auditFundCommittee(row) {
      this.resetFormFundCommittee();
      this.formFundCommittee.id=row.id;
      this.openFundCommittee = true;
      this.title = "基金管委会审核";

    },
    /** 二级工会审核 */
    submitForm() {
      if(this.form.status=='1' && (this.form.opinion ==""|| this.form.opinion ==null)){
        this.$modal.msgWarning("审核意见不能为空");
        return false;
      }
      auditSecondLaborUnion(this.form).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
      });
    },
    /**基金管委会审核***/
    submitFundCommittee() {
      if(this.formFundCommittee.status=='4' && (this.formFundCommittee.opinion ==""|| this.formFundCommittee.opinion ==null)){
        this.$modal.msgWarning("审核意见不能为空");
        return false;
      }
      auditFundCommittee(this.formFundCommittee).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.openFundCommittee = false;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除退会申请记录编号为"' + ids + '"的数据项？').then(function() {
        return delAppWithdrawal(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/appWithdrawal/expAppWithdrawal', {
        ...this.queryParams
      }, `武汉理工大学重大疾病医疗互助基金申请退会人员汇总表${new Date().getTime()}.pdf`)
    }
  }
};
</script>
